var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    // 代码映射图,方便调试
    devtool: 'eval-source-map',
    // 开发模式选择,共两种,分别是"development"和"production"
    mode: 'development',
    // 多入口文件
    entry: {
        // 干扰物部署的入口文件
        deploy: './src/js/deploy.js',
        // 开关假目标的入口文件
        switch: './src/js/switch.js',
        // 部署假目标的入口文件
        fake: './src/js/fake.js'

    },
    output: {
        // 默认输出为dist目录下的"入口.js"文件
        filename: './js/[name].js'
    },
    plugins: [
        // html代码热加载
        new HtmlWebpackPlugin({
            filename: './deploy.html',
            template: './src/deploy.html',
            chunks: ['deploy'],
            inject: 'body',
        }),
        // html代码热加载
        new HtmlWebpackPlugin({
            filename: './fake.html',
            template: './src/fake.html',
            chunks: ['fake'],
            inject: 'body',
        }),
        // html代码热加载
        new HtmlWebpackPlugin({
            filename: './switch.html',
            template: './src/switch.html',
            chunks: ['switch'],
            inject: 'body',
        }),
        // 将目录中的文件复制到指定位置
        new CopyWebpackPlugin(
            [
                {
                    from: './src/css',
                    to: './css',
                    toType: 'dir'
                },
                {
                    from: './src/fonts',
                    to: './fonts',
                    toType: 'dir'
                },
                {
                    from: './src/imgs',
                    to: './imgs',
                    toType: 'dir'
                }
            ]
            , {debug: 'info'})
    ],
    module: {
        rules: [
            {
                test: /\.js$/,
                use: 'babel-loader',
                exclude: '/node_modules/'
            }
        ]
    },
    // 开发时使用的服务器
    devServer: {
        contentBase: "./dist/",
        port: 9000,
        inline: true,
        open:true
    }
};
